package cn.iocoder.yudao.module.api.pay.order.eums;

import cn.iocoder.yudao.framework.business.basic.enums.EnumCodable;
import com.baomidou.mybatisplus.annotation.EnumValue;
import jakarta.annotation.Nonnull;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 支付渠道的编码的枚举
 *
 * @author 芋道源码
 */
@Getter
@AllArgsConstructor
public enum UnifiedPayChannelEnum implements EnumCodable {

    UNKNOWN("undefined", "未知"),

    WX_PUB("wx_pub", "微信 JSAPI 支付"), // 公众号网页
    WX_LITE("wx_lite", "微信小程序支付"),
    WX_APP("wx_app", "微信 App 支付"),
    WX_NATIVE("wx_native", "微信 Native 支付"),
    WX_WAP("wx_wap", "微信 Wap 网站支付"), // H5 网页
    WX_BAR("wx_bar", "微信付款码支付"),

    ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付"),
    ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付"),
    ALIPAY_APP("alipay_app", "支付宝App 支付"),
    ALIPAY_QR("alipay_qr", "支付宝扫码支付"),
    ALIPAY_BAR("alipay_bar", "支付宝条码支付"),

    MALLBOOK_WX_LITE("mallbook_wx_ite", "MallBook 微信小程序支付"),

    WALLET("wallet", "钱包支付"),
    MOCK("mock", "模拟支付"),
    CASH("cash", "现金支付"),
    FREE("free", "免支付"),
    ;

    @EnumValue
    private final String code;
    private final String name;

    @Nonnull
    public static UnifiedPayChannelEnum getByCode(String code) {
        return Arrays.stream(values())
                .filter(it -> Objects.equals(it.code, code))
                .findFirst()
                .orElse(UNKNOWN);
    }

    public static boolean isWxLite(String code) {
        return WX_LITE.getCode().equalsIgnoreCase(code) ||
               MALLBOOK_WX_LITE.getCode().equalsIgnoreCase(code);
    }

}
